package com.smallsoft.adapter;

import java.util.ArrayList;

import com.smallsoft.beans.Category;
import com.smallsoft.util.ImageViewRounded;
import com.smallsoft14.phongtucvietnam.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MenuAdapter extends BaseAdapter{

	Context context;
	LayoutInflater layoutInflater;
	ArrayList<Category> categories = new ArrayList<Category>();
	private int[] images;
	
	public MenuAdapter(Context context, ArrayList<Category> categories){
		this.categories = categories;
		this.context = context;
		layoutInflater = LayoutInflater.from(context);
		init();
	}
	
	private void init(){
		this.images = new int[] {
				R.drawable.cuoihoi,
				R.drawable.sinhduong,
				R.drawable.giaothiep,
				R.drawable.daohieu,
				R.drawable.tangle,
				R.drawable.tet,
				R.drawable.chonngaygio,
		};
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return categories.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return categories.get(position);
	}

	@Override
	public long getItemId(int id) {
		// TODO Auto-generated method stub
		return id;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup viewGroup) {
		// TODO Auto-generated method stub
		Category category = categories.get(position);
		layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if(convertView == null){
			convertView = layoutInflater.inflate(R.layout.list_menu_item, viewGroup, false);
		}
		TextView name = (TextView)convertView.findViewById(R.id.name);
		ImageViewRounded icon = (ImageViewRounded)convertView.findViewById(R.id.icon);
		icon.setImageResource(images[position]);
		name.setText(category.getName());
		return convertView;
	}

}
